#!/usr/bin/env bash
# https://cirosantilli.com/cirodown#do-the-release
set -eux
if [ $# -lt 1 ]; then
  version="$(./inc-version)"
else
  version="$1"
fi
# Although this is also run by `npm run publish`, it is also
# required for some tests to pass so we have to run it here too.
npm run build-assets
npm test
# This also does npm run build-assets
npm run publish
sed -i "s/  \"version\":.*/  \"version\": \"${version}\",/" package.json
# To update the package-lock.json.
# Not sure why needed twice, some mess with link madness.
npm run link
npm run link
git add -u
git commit -m "version $version"
git tag -m "$version" "$version"
git push --follow-tags
npm publish
./update-templates
